package com.lian.servlet;

import com.lian.dao.impl.staffdaoimpl;
import com.lian.dao.impl.workdaoimpl;
import com.lian.dao.staffdao;
import com.lian.dao.workdao;
import com.lian.entity.product;
import com.lian.entity.staff;
import com.lian.entity.user;
import com.lian.entity.work;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by lenovo on 2018/8/9.
 */
public class updateServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        request.setCharacterEncoding("utf-8");
        user us=new user();
        int uid=Integer.parseInt(request.getParameter("uname")); //uid


        staff st=new staff();
        staffdao dao2=new staffdaoimpl();

        int staffid=dao2.findID(uid);
        st.setUserid(uid);//安装员的id  user和sraff表关联 的字段  userid

        st.setStaffid(staffid);//根据uid查询出staff 表的 staffid

        product pr=new product();

        int wpid=Integer.parseInt(request.getParameter("waterName"));

        work wo=new work();
        int workid=Integer.parseInt(request.getParameter("workid"));
        wo.setWorkid(workid);
        wo.setStaffid(staffid);//获取安装员名字
        wo.setWpid(wpid);//获取净水器名称
        wo.setUserName(request.getParameter("userName"));
        wo.setUserPhone(request.getParameter("userPhone"));
        wo.setUserAddress(request.getParameter("userAddress"));
        wo.setWorkType(Integer.parseInt(request.getParameter("workType")));
        wo.setStatus(Integer.parseInt(request.getParameter("status")));
        workdao dao=new workdaoimpl();
        int i=dao.updwork(wo);
        if(i>0){
            out.print("<script language='javascript'>" +
                    "var index = parent.layer.getFrameIndex(window.name);\n" +
                    "  window.parent.location.reload();\n"+
                    "  parent.layer.close(index);\n"+
                    "</script>");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
